package com.fr.report.script.function;

import com.fr.base.FRContext;
import com.fr.base.StringUtils;
import com.fr.report.script.Function;
import com.fr.report.script.Function.Type;
import com.fr.report.script.NormalFunction;
import com.fr.report.script.Primitive;
import java.util.logging.Level;
import java.util.logging.Logger;

public class TOINTEGER extends NormalFunction
{
  public Object run(Object[] paramArrayOfObject)
  {
    if (paramArrayOfObject.length < 1)
      return Primitive.ERROR_NAME;
    return new Integer(0);
  }

  private Number object2Number(Object paramObject)
  {
    if (paramObject == null)
      return new Integer(0);
    String str = paramObject.toString();
    if (StringUtils.isBlank(str))
      return new Integer(0);
    try
    {
      return Double.valueOf(str);
    }
    catch (NumberFormatException localNumberFormatException)
    {
      FRContext.getLogger().log(Level.WARNING, localNumberFormatException.getMessage(), localNumberFormatException);
    }
    return new Integer(0);
  }

  private Number number2Int(Number paramNumber)
  {
    if (paramNumber == null)
      return new Integer(0);
    int i = paramNumber.intValue();
    long l = paramNumber.longValue();
    if (i == l)
      return new Integer(i);
    return new Long(l);
  }

  public Function.Type getType()
  {
    return Function.TEXT;
  }

  public String getCN()
  {
    return "TOINTEGER(text): 将文本转换成Integer对象。\nText:需要转换的文本。\n示例:\nTOINTEGER(\"123\")等于 new Integer(123)。";
  }

  public String getEN()
  {
    return "TOINTEGER(text): Convert text to Integer object.\n\nExample:\nTODOUBLE(\"123\") = new Integer(123)。";
  }
}